const fs = require('fs')

// const useRouters = (app) => {
//   //读取当前目录所有的文件
//   fs.readdirSync(__dirname).forEach(file => {
//     if(file === 'index.js') return;
//     const router = require(`./${file}`)
//     //动态导入文件并且赋值给router
//     app.use(router.routes())
//     app.use(router.allowedMethods())
//   })
// }

const useRouters = function() {
  fs.readdirSync(__dirname).forEach(file => {
    if(file === 'index.js') return;
    const router = require(`./${file}`)
    this.use(router.routes())
    this.use(router.allowedMethods())
  })
}

module.exports = useRouters